#include <stdio.h>
#include <stdlib.h>
int a[4], flag, count;
prt()
{
    printf("Now your number must be %d%d%d%d.\n", a[0], a[1], a[2], a[3]);
    printf("Game Over\n");
}


int main()
{
    int b1, b2, i, j, k = 0, p, c;
    printf("Game Begin\n");
    printf("Now guess your number in mind is ####.\n");
    for (i = 1; i < 10 && k < 4; i++)
    {
        printf("No.%d:your number may be :%d%d%d%d\n", ++count, i, i, i, i);
        printf("How many digits have had correctly guessed:");
        scanf("%d", &p);
        for (j = 0; j < p; j++)
            a[k + j] = i;
        k += p;
    }
    if (k < 4)
        for (j = k; j < 4; j++)
            a[j] = 0;
    i = 0;
    printf("No.%d:your number may be:%d%d%d%d\n",
           ++count, a[0], a[1], a[2], a[3]);
    printf("How many are in exact positions:");
    scanf("%d", &b1);
    if (b1 == 4)
    {
        prt();
        exit(0);
    }
    for (flag = 1,j = 0; j < 3 && flag; j++)
        for (k = j + 1; k < 4 && flag; k++)
            if (a[j] != a[k])
            {
                c = a[j];
                a[j] = a[k];
                a[k] = c;
                printf("No.%d:your number may be: %d%d%d%d\n",
                       ++count, a[0], a[1], a[2], a[3]);
                printf("How many are in exact positions:");
                scanf("%d", &b2);
                if (b2 == 4)
                {
                    prt();
                    flag = 0;
                }
                else if (b2 - b1 == 2)
                    bhdy(j, k);
                else if (b2 - b1 == -2)
                {
                    c = a[j];
                    a[j] = a[k];
                    a[k] = c;
                    bhdy(j, k);
                }
                else if (b2 <= b1)
                {
                    c = a[j];
                    a[j] = a[k];
                    a[k] = c;
                }
                else
                    b1 = b2;
            }
    if (flag)
        printf("You input error!\n");

    return 0;
}

bhdy(s, b) 
    int s, b;
{
    int i, c = 0, d[2];
    for (i = 0; i < 4; i++)
        if (i != s && i != b)
            d[c++] = i;
    i = a[d[1]];
    a[d[1]] = a[d[0]];
    a[d[0]] = i;
    prt();
    flag = 0;
}

//熊贤豪